package cn.com.guage.dtm.huawei;

import java.util.HashMap;
import java.util.Scanner;
import java.util.TreeMap;

public class HJ8_合并表记录 {
    public static void main(String[] args) throws Exception{
        method2();
    }

    private static void method1(){
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < num; i++) {
            int k = scanner.nextInt();
            int v = scanner.nextInt();
            map.merge(k, v, Integer::sum);
        }
        map.keySet().stream().sorted().forEach(k -> System.out.println(k + " " + map.get(k)));
    }

    private static void method2(){
        Scanner sc = new Scanner(System.in);
        TreeMap<Integer, Integer> map = new TreeMap<>(); // 输出结果要求有序！
        while(sc.hasNextInt()){
            int n = sc.nextInt();
            for(int i = 0; i < n; ++i){
                int a = sc.nextInt();
                int b = sc.nextInt();
                map.put(a,map.getOrDefault(a,0) + b);
            }
        }
        for (Integer i : map.keySet()) {
            System.out.println(i + " " + map.get(i));
        }
    }
}
